package com.tmjavabasics.mythreads;

import java.util.Date;
import java.util.Random;

public class ThreadOne extends Thread {
	private SharedData sharing;

	public SharedData getSharing() {
		return sharing;
	}

	public void setSharing(SharedData sharing) {
		this.sharing = sharing;
	}

	public ThreadOne(String name) {
		super(name);
	}

	@Override
	public void run() {
		while (true) {
			try {
				Thread.sleep((int) ((new Random()).nextDouble() * 500));
				sharing.showData(String.format("%s Date: %tT", getName(),
						(new Date())));
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
